using Digitalmes.Application.Mes.Equipments.InspectManuals;
using Digitalmes.Application.Mes.Equipments.InspectManuals.Commands;
using Digitalmes.Application.Mes.Equipments.InspectManuals.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Equipments;

/// <summary>
/// 手动点检终结点。
/// </summary>
public sealed class ManualInspectEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/equipment/inspect", "manual")
            .RequireAuthorization()
            .MapGet(GetAllManualInspectionPlanListAsync, "plan/list")
            .MapGet(GetManualInspectionPlanAsync, "plan")
            .MapPost(ManualInspectAsync);
    }

    [EndpointDescription("查询所有的手动点检计划，其中包含设备具体信息")]
    public async Task<IApiResult> GetAllManualInspectionPlanListAsync(ISender sender, [AsParameters] GetAllManualInspectionPlanListQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }


    [EndpointDescription("获取指定设备的手动点检计划，包含点检项目清单")]
    public async Task<IApiResult> GetManualInspectionPlanAsync(ISender sender, [AsParameters] GetManualInspectionPlanQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("手动点检")]
    public async Task<IApiResult> ManualInspectAsync(ISender sender, ManualInspectInput input)
    {
        var result = await sender.Send(new ManualInspectCommand(input));
        return result.ToApiResult();
    }
}
